package com.agou.core.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class UtSecurity {

	// MD5编码
	public static String md5Coding(String str) {
		byte[] strByte = str.getBytes();
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		md.update(strByte);
		byte[] newByte = md.digest();
		StringBuilder sb = new StringBuilder();
		// 转换为16进制
		for (int i = 0; i < newByte.length; i++) {
			if ((newByte[i] & 0xff) < 0x10) {
				sb.append("0");
			}
			sb.append(Long.toString(newByte[i] & 0xff, 16));
		}
		return sb.toString();
	}

}
